package com.btkjgc.service.impl;

import com.btkjgc.models.Dictionary;
import com.btkjgc.service.intf.DictionaryService_Intf;
import com.btkjgc.utils.HibernateUtil;

import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * Created by HelloWorld on 2015/4/21.
 */
@Service
public class DictionaryService_Impl implements DictionaryService_Intf
{
	@SuppressWarnings("unchecked")
	@Override
	public HashMap<String, String> getDictoinaryByName(String name)
	{
		String hql = "from Dictionary where name = ?";
		String para[] = { name };
		List<Dictionary> dictionaryTList = (List<Dictionary>) HibernateUtil
				.executeQueryList(hql, para);
		HashMap<String, String> map = new HashMap<String, String>();
		for (Dictionary dictionaryT : dictionaryTList)
		{
			map.put(dictionaryT.getKey(), dictionaryT.getValue());
		}
		return map;

	}

	@SuppressWarnings("unchecked")
	@Override
	public List<String> getDictoinaryValuesByName(String name)
	{
		String hql = "select value from Dictionary where name = ?";
		String para[] = {name };
		return (List<String>) HibernateUtil.executeQueryList(hql, para);
	}

	@Override
	public Integer getDictoinaryKeyByName(String value,String name)
	{
		String hql = "select key from Dictionary wher name = ? and value = ?";
		String para[] = {name, value };
		Object obj = HibernateUtil.executeQueryOneObject(hql, para);
		return (Integer) obj;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Dictionary> getDictionaryByName(String name)
	{
		String hql = "from Dictionary where   name = ?";
		String[] param = {  name };
		return HibernateUtil.executeQueryList(hql, param);
	}
}
